from datetime import datetime
from typing import Any, Optional
from pydantic import BaseModel, Field

from .task_data import TaskStatus


class ProgressData(BaseModel):
    """任务进度数据模型"""

    task_id: str = Field(..., description="任务ID")
    progress: float = Field(..., description="进度百分比(0-100)")
    status: TaskStatus = Field(..., description="任务状态")
    message: str = Field(default="", description="进度消息")
    details: dict[str, Any] = Field(default_factory=dict, description="详细信息")
    start_time: Optional[datetime] = Field(default=None, description="开始时间")
    end_time: Optional[datetime] = Field(default=None, description="结束时间")
    eta: Optional[float] = Field(default=None, description="预计剩余时间(秒)")
    steps_completed: int = Field(default=0, description="已完成步骤数")
    total_steps: int = Field(default=0, description="总步骤数")
    subtasks: dict[str, float] = Field(default_factory=dict, description="子任务进度")
    timestamp: datetime = Field(default_factory=datetime.now, description="时间戳")

    class Config:
        json_encoders = {datetime: lambda v: v.isoformat() if v else None}
